$(function(){
	new Vue({
		el:'#addManagerApp',
		data:{
			fullscreenLoading:false,
			uploadUrl:"http://39.100.131.147:8888/goods/address/uploadFile",
			fileList:[],
			form:{
				name:"",
				source:"",
				value:"",
				date1:"",
				time1:"",
				date2:"",
				time2:"",
			}
		},
		created:function(){
			
		},
		methods:{
			isNotNumber(inputData) {
				if (parseFloat(inputData).toString() == "NaN") {
					return false;
				} else {
					return true;
				}
			},
			configManagerSuper(){
				  if(stringEmpty(this.form.name)){
					this.$message.error('优惠券名称不能为空');
					return
				  }
				  if(stringEmpty(this.form.source)){
				  	this.$message.error('活动名称不能为空');
				  	return
				  }
				  if (!this.isNotNumber(this.form.value)) {
				  	 this.$message.error('优惠券金额只能为数字');
				  	return;
				  }
				  if(stringEmpty(this.form.date1)|| stringEmpty(this.form.time1)){
				  	this.$message.error('优惠券开始日期不能为空');
				  	return
				  }
				  if(stringEmpty(this.form.date2)|| stringEmpty(this.form.time2)){
				  	this.$message.error('优惠券结束日期不能为空');
				  	return
				  }
				  
				  let startStr  = this.form.date1+" " + this.form.time1+ ":000"
				  let starDate = new Date(startStr);
				  let beginTime = Date.parse(starDate)/1000
				  
				  let endStr =  this.form.date2 + " " + this.form.time2+ ":000"
				  let endDate = new Date(endStr)
				  let overTime = Date.parse(endDate)/1000
				  
				  if(beginTime > overTime){
					this.$message.error('优惠券开始日期不能大于结束日期');
					return  
				  }
				  
				   let upForm = {}
				   upForm.name  = this.form.name
				   upForm.value = regYuanToFen(this.form.value,100)
				   upForm.source = this.form.source
				   upForm.beginTime = beginTime
				   upForm.overTime  = overTime
				  
				  this.fullscreenLoading = true;
				  axios({
				  	url: POSTURL.addCouponsTemplate,
				  	method: 'post',
				  	data: upForm
				  }).then(response => {
				  	this.fullscreenLoading = false;
				  	if (response.data.code === 100) {
				  		this.$message({
				  			showClose: true,
				  			message: response.data.message,
				  			type: 'success'
				  		});
						this.form ={};
				  	} else {
				  		this.$message.error(response.data.message);
				  	}
				  }).catch(error => {
				  	this.fullscreenLoading = false;
				  	console.log(error);
				  	this.$message.error('服务器出错!');
				  })
			},
		}
	})
})